
import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/page/my/order/cancel_order/cancel_order_view.dart';
import 'package:flutter_ncsjqz_getx/util/math_util.dart';
import 'package:flutter_ncsjqz_getx/widget/app_bar_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/card_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/ink_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/row_line_widget.dart';
import 'package:get/get.dart';

import '../order_view.dart';
import 'after_info_logic.dart';

/// <summary>
/// todo: 售后详情
/// author：zwb
/// dateTime： 2021/11/10 18:09
/// filePath： lib/page/my/order/after_info/after_info_view.dart
/// desc:
/// <summary>
///
class AfterInfoPage extends StatefulWidget {
  OrderModel? orderModel;
  AfterInfoPage({this.orderModel});
  @override
  _AfterInfoPageState createState() => _AfterInfoPageState();
}

class _AfterInfoPageState extends State<AfterInfoPage> {
  final logic = Get.put(AfterInfoLogic());

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // 退款成功  省略进度条
    if(widget.orderModel!.status == 32 || widget.orderModel!.status == 41){
      logic.setAfterStatus(AfterEnum.TKCG);
    }
    logic.getDetails(widget.orderModel!.id);
  }
  @override
  Widget build(BuildContext context) {
    print(MathUtil.getMax(2,5));
    return GetBuilder<AfterInfoLogic>(
      builder: (controller) {
        return Scaffold(
          backgroundColor: Colors.white,
          appBar: appBarWidget(title: "售后详情"),
          body: ListView(
            padding: EdgeInsets.all(15),
            children: [
              /// 退订单进度
              orderStatus(),

              /// 订单提示
              orderMeg(),

              /// 订单信息
              orderInfo(),

            ],
          ),
          bottomNavigationBar: Offstage(
            child: Container(
              width: Get.width,
              height: 75,
              padding: EdgeInsets.symmetric(vertical: 15,horizontal: Get.width * 0.15),
              child: OutlineButton(
                child: InkWidget.text(widget.orderModel!.status == 30? "撤销申请":"重新申请退款",color: Colors.green),
                borderSide: BorderSide(color: Colors.green,),
                shape: StadiumBorder(),
                onPressed: (){
                  if(widget.orderModel!.status == 30){

                  }else{
                    Get.to(()=>CancelOrderPage(orderModel: widget.orderModel,));
                  }
                },
              ),
            ),
            offstage: logic.status==AfterEnum.TKCG,
          ),
        );
      },
    );
  }

  orderStatus() {
    return Container(
      width: Get.width,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Offstage(
                    child: InkWidget.imgAsset("select.png",width: 15),
                    offstage: logic.status!=AfterEnum.TKCG,
                  ),
                  InkWidget.title(statusText()),
                ],
              ),
              // InkWidget.text("还剩23小时59分",color: Colors.grey),
            ],
          ),

          SizedBox(height: 15,),

          Offstage(
            offstage: logic.status==AfterEnum.TKCG,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Stack(
                  overflow: Overflow.visible,
                  children: [
                    Container(
                      width: Get.width - 80,
                      height: 1,
                      color: Colors.grey.shade300,
                    ),
                    Positioned(
                      top: -(15 / 2),
                      left: -25,
                      child: Column(
                        children: [
                          Container(
                            width: 15,
                            height: 15,
                            decoration: BoxDecoration(
                              border: Border.all(color: 1==1 ?Colors.green:Colors.grey.shade300),
                              borderRadius: BorderRadius.circular(15),
                              color: Colors.white,
                            ),
                          ),
                          InkWidget.text("提交申请",color: Colors.grey),
                        ],
                      ),
                    ),
                    Positioned(
                      top: -(15 / 2),
                      left: ((Get.width - 60) / 2) - (25+7.5),
                      child: Column(
                        children: [
                          widget.orderModel!.status == 33 || widget.orderModel!.status == 32 ?  Container(
                        width: 15,
                        height: 15,
                        decoration: BoxDecoration(
                          border: Border.all(color: Colors.green),
                          borderRadius: BorderRadius.circular(15),
                          color: Colors.white,
                        ),
                      ):ClipOval(
                            child: Container(
                              width: 15,
                              height: 15,
                              color: Colors.green,
                            ),
                          ),
                          InkWidget.text("商家处理",color:widget.orderModel!.status == 30 ?Colors.green: Colors.grey),
                        ],
                      ),
                    ),
                    Positioned(
                      top: -(15 / 2),
                      right: -25,
                      child: Column(
                        children: [
                          ClipOval(
                            child: Container(
                              width: 15,
                              height: 15,
                              color: widget.orderModel!.status == 33 || widget.orderModel!.status == 32 ?Colors.green:Colors.grey.shade300,
                            ),
                          ),
                          InkWidget.text(widget.orderModel!.status == 33 ?"拒绝退款":"退款成功",color: Colors.grey),
                        ],
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),

          Offstage(
            offstage: logic.status==AfterEnum.TKCG,
            child: SizedBox(height: 40,),
          ),

          // 进度条
          // Container(
          //   width: Get.width - 40,
          //   height: 50,
          //   child: ListView(
          //     shrinkWrap: true,
          //     padding: EdgeInsets.symmetric(horizontal: 15),
          //     scrollDirection: Axis.horizontal,
          //     children: List.generate(3, (index){
          //       return Container(
          //         child: Stack(
          //           overflow: Overflow.visible,
          //           children: [
          //             Container(
          //               width: index == 2 ? 1 : (Get.width / 2) - 40,
          //               height: 1,
          //               color: Colors.grey,
          //             ),
          //             Positioned(
          //               top: -15/2,
          //               child: ClipOval(
          //                 child: Container(
          //                   width: 15,
          //                   height: 15,
          //                   color: widget.orderModel!.status == 33 || widget.orderModel!.status == 32 ?Colors.green:Colors.grey.shade300,
          //                 ),
          //               ),
          //             ),
          //             Positioned(
          //               top: 20,
          //               left: -20,
          //               child: InkWidget.text(widget.orderModel!.status == 33 ?"拒绝退款":"退款成功",color: Colors.grey),
          //             ),
          //           ],
          //         ),
          //       );
          //     })
          //     ,
          //   ),
          // ),
        ],
      ),
    );
  }

  orderMeg(){
    return Offstage(
      offstage: logic.status==AfterEnum.TKCG,
      child: cardWidget(
        width: Get.width,
        padding: EdgeInsets.all(15),
        margin: EdgeInsets.symmetric(vertical: 5,),
        widget: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            InkWidget.title("你已成功发起取消订单申请，请耐心等待处理",fonSize: 16),
            SizedBox(height: 10,),
            InkWidget.text("商家已同意或者超时未处理，系统将退款给您",maxLines: 999,color: Colors.grey,fonSize: 14),
            InkWidget.text("如果商家拒绝，您可以修改退款申请后再次发起，商家会重新处理",maxLines: 999,color: Colors.grey,fonSize: 14),
          ],
        ),
      ),
    );
  }

  orderInfo() {
    return cardWidget(
      width: Get.width,
      widget: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [

          Padding(
            child: InkWidget.title("订单信息",fonSize: 16),
            padding: EdgeInsets.all(15),
          ),

          Padding(
            child: Row(
              children: [
                InkWidget.imgNet('${widget.orderModel!.img}',width: 100,height: 100,fit: BoxFit.cover,borderRadius: BorderRadius.circular(5)),
                Container(
                  width: Get.width - 100 - 60, // 减去 图片宽度+间隙
                  height: 100, // 和图片同步高度
                  padding: EdgeInsets.only(left: 10),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      InkWidget.title("${widget.orderModel!.title }",maxLines: 2,fonSize: 16),

                      InkWidget.text("规格：${widget.orderModel!.sku}  数量：${widget.orderModel!.count}",maxLines: 2,fonSize: 12,color: Colors.grey),
                    ],
                  ),
                ),
              ],
            ),
            padding: EdgeInsets.symmetric(horizontal: 15),
          ),

          rowBaseWidget(
            padding: EdgeInsets.all(15),
            leftText: "退款金额",
            right: InkWidget.title("￥${widget.orderModel!.price}",color: Colors.red),
          ),

          rowBaseWidget(
            padding: EdgeInsets.all(15),
            leftText: "申请时间",
            rightText: "${logic.refundDetailsData.handelTime}",
            showRightIcon: false,
          ),

          rowBaseWidget(
            padding: EdgeInsets.all(15),
            leftText: "订单号 ",
            rightFlex: 4,
            rightText: "${widget.orderModel!.orderNo ??''}",
            showRightIcon: false,
          ),
        ],
      ),
    );
  }

  /// 右上角状态标识
  statusText() {
    String text = "";
    Color textColor = Colors.white;
    // ORDER_INIT(10, "初始化"),
    // ORDER_WAIT_PAY(11, "等待支付"),
    // ORDER_PAY_FAIL(12, "支付失败"),
    // ORDER_CANCEL(13, "取消订单"),
    // ORDER_PAY_SUCCESS(14, "支付成功"),
    //
    // WAIT_DELIVER_GOODS(20, "等待发货"),
    // WAIT_RECEIVE(21, "待收货"),
    // APPLY_CANCEL_ORDER(22, "申请退货"),
    // REJECT_CANCEL_ORDER(23, "拒绝退货"),
    //
    // WAIT_REFUND(30, "等待退款"),
    // REFUNDED(31, "商家已退款"),
    // PLATFORM_REFUNDED(32, "平台同意退款"),
    // REJECT_REFUNDED(33, "平台拒绝退款"),
    //
    // WAIT_EVALUATE(41, "等待评价"),
    // EVALUATE_NEED(42, "已评价"),
    //
    // ORDER_CLOSE(99, "订单关闭");
    if(widget.orderModel!.status == 11){
      text = "待付款"; // 5分钟未支付自动取消订单
      textColor = Colors.red;
    }
    if(widget.orderModel!.status == 41){
      text = "已完成";
      textColor = Colors.green;
    }
    if(widget.orderModel!.status == 22){
      text = "申请退货";
      textColor = Colors.black45;
    }
    if(widget.orderModel!.status == 30){
      text = "等待退款";
      textColor = Colors.black45;
    }
    if(widget.orderModel!.status == 32){
      text = "平台同意退款";
      textColor = Colors.black45;
    }
    if(widget.orderModel!.status == 33){
      text = "平台拒绝退款";
      textColor = Colors.red;
    }
    if(widget.orderModel!.status == 13){
      text = "已取消";
      textColor = Colors.black45;
    }
    return text;
  }

  @override
  void dispose() {
    Get.delete<AfterInfoLogic>();
    super.dispose();
  }


}